﻿using Rhino.Geometry;

namespace AiMoCore
{
    //给写代码时候用的补充
    public static class AimoStaticUtils
    {
        public static Brep ToBrep(this Circle circle)
        {
            return Brep.CreateTrimmedPlane(circle.Plane, circle.ToNurbsCurve());
        }
        public static Brep ToBrep(this Rectangle3d rec)
        {
            return Brep.CreateTrimmedPlane(rec.Plane, rec.ToNurbsCurve());
        }
        public static Brep ToBrep(this Curve crv)
        {
            if (crv != null && crv.IsClosed && crv.TryGetPlane(out Plane plane))
            {
                return Brep.CreateTrimmedPlane(plane, crv);
            }
            return null;
        }
        public static Brep ToBrep(this Polyline pl)
        {
            if (pl != null && pl.IsClosed && pl.Count > 2)
            {
                Curve crv = pl.ToNurbsCurve();
                if (crv.TryGetPlane(out Plane plane, 0.001))
                {
                    return Brep.CreateTrimmedPlane(plane, crv);
                }
                else
                {
                    Mesh mesh = Mesh.CreateFromClosedPolyline(pl);
                    return Brep.CreateFromMesh(mesh, true);
                }
            }
            return null;
        }
        public static Brep ToBrep(this Ellipse ellipse)
        {
            return Brep.CreateTrimmedPlane(ellipse.Plane, ellipse.ToNurbsCurve());
        }

    }
}
